package com.example.plane.spirit;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;

import com.example.plane.GameActivity;
import com.example.plane.MainActivity;

public class Spirit {
    public Bitmap bitmap,ybitmap;
    public int hpwidth;
    public int hpheight;
    public int hpx;
    public int hpy;
    public Paint p=new Paint();
    public Buttle hpbuttle=new Buttle();
    private float scaleWidth;
    private float scaleHeight;
    private final int thisScreenwidth=1080;
    private final int thisSCreenheight=1776;
    private final float scalemyplanex= (float) 0.7;
    private final float scalemyplaney= (float) 0.7;
    public Spirit(){

    }
    public void initView( Bitmap wbitmap){
        ybitmap= wbitmap;
        scaleWidth = (float) ((((float) GameActivity.Scrrenwidth)/ thisSCreenheight)*scalemyplanex);//计算宽度的缩放比例
        scaleHeight = (float) ((((float) GameActivity.Screenheight)/ thisSCreenheight)*scalemyplaney);//计算高度的缩放比例
        Matrix matrix = new Matrix();//矩阵类用于图像坐标的转换，以及旋转，缩放等特殊操作。
        matrix.postScale(scaleWidth, scaleHeight);//设置缩放
        //如果将实例化在外面即不释放内存，该对象会一直缩放
        hpwidth=ybitmap.getWidth();
        hpheight=ybitmap.getHeight();
        bitmap= Bitmap.createBitmap(ybitmap, 0, 0,hpwidth, hpheight, matrix, false);//创建一个缩放后的图片
    }
    public void Draw(Canvas canvas)
    {
        canvas.drawBitmap(bitmap,hpx, hpy, p);
    }
}
